/**
 * Copyright (C) 2011 The Android Open Source Project 
 * Emial : guoyil199@163.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package com;

/**
 * @author THINK
 * @Email guoyil199@163.com
 * @version V1.0
 * @Date 2016年5月27日 下午2:19:07
 * @Title <B>todo</B>
 * 
 *        <pre>
 * todo
 * </pre>
 */

public class Single_Extends_Test {
	public static void main(String[] args) {
		// Single s = new Single(); 这个实例化是要调用Single的构造函数，被privat修饰，不能实例化
		// Single s = new Single2(); 这个是调用的Single的子类来实例化
		//Single s = new Single(3); // 显示的通过另一个构造函数来实例化
		//s.print();
		Single s=Single2.getInstance();
		s.print();
		
		Single s1=Single.getInstance();
		s1.print();
	}
}

class Single {
	private static Single s = new Single();

	private Single() {
	}

	public static Single getInstance() {
		return s;
	}

	public void print() {
		System.out.println("饿汉式——单例设计模式");
	}

	Single(int x) // 这个没有定义成私有
	{
		System.out.println("Single");
	}
}

class Single2 extends Single {
	Single2() {
		super(3); // 在继承中，在子类的构造函数中，也会调用父类的构造函数，如果没有指明，
					// 则会是默认的super();
		System.out.println("测试");
	}
	
	public void print() {
		System.out.println("饿汉式——单例设计模式");
	}
}